<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <script src="https://cdn.jsdelivr.net/npm/vue"></script>
    <style>
        * {
            margin: 0;
            padding: 0;
            list-style: none;
        }
        
        .header {
            margin-bottom: 20px;
            width: 300px;
            height: 50px;
            background-color: tan;
            display: flex;
        }
        
        .l,
        .r {
            width: 50px;
            height: 50px;
            background-color: skyblue;
            text-align: center;
            line-height: 50px;
            font-family: "宋体";
        }
        
        .c {
            flex: 1;
            text-align: center;
            line-height: 50px;
        }
        
        .c ul {
            display: flex;
            justify-content: space-around;
        }
    </style>
</head>

<body>
    <!--
        插槽的作用： 提高组件的复用性和可扩展性，使组件变灵活

        而组件是提高了代码的复用性
     
    -->
    <div id="app">
        <my-header>
            <input type="text" placeholder="输入搜索内容" slot="ipt">
            <h3 slot="car">购物车</h3>
            <ul slot="list">
                <li>评价</li>
                <li>详情</li>
                <li>推荐</li>
            </ul>
        </my-header>
    </div>
</body>

<template id="tmpl">
    <div>
        <div class="header">
            <div class="l">&lt;</div>
            <div class="c">
                <!-- <slot name="ipt"></slot>
                <slot name="car"></slot>
                <slot name="list"></slot> -->
                <slot :name="slotName"></slot>
            </div>
            <div class="r">...</div>
        </div>
        <button @click="tab('ipt')">搜索</button>
        <button @click="tab('car')">购物车</button>
        <button @click="tab('list')">列表</button> 
    </div>
    
</template>

<script>
    let myHeader = {
        template: '#tmpl',
        data() {
            return {
                slotName: 'ipt'
            }
        },
        methods: {
            tab(val) {
                this.slotName = val
            }
        },
    }

    var vm = new Vue({
        el: '#app',
        data: {},
        components: {
            myHeader
        }
    })
</script>

</html>